def count_palindromic_subsequences(s: str) -> int:
    MOD = 10**9 + 7
    n = len(s)
    # 初始化动态规划表
    dp = [[0] * n for _ in range(n)]
    
    # 填充动态规划表
    for i in range(n-1, -1, -1):
        dp[i][i] = 1
        for j in range(i+1, n):
            if s[i] == s[j]:
                dp[i][j] = (dp[i+1][j] + dp[i][j-1] + 1) % MOD
            else:
                dp[i][j] = (dp[i+1][j] + dp[i][j-1] - dp[i+1][j-1]) % MOD
    
    return dp[0][n-1] % MOD

s = "aba"
print(count_palindromic_subsequences(s))